From 2d3a7bd4f9b359a86638dc07665909868176cc95 Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Tue, 24 Feb 2004 11:35:44 +0000 Subject: [PATCH] bitkeeper revision 1.743 (403b37106MV2R0Wr2iE98QHJWFPRMw) trace.h, dom0_ops.h, trace.c, setup.c, xentrace.c, Makefile: Cleanups to new trace code. --- tools/xentrace/Makefile | 2 +- tools/xentrace/xentrace.c | 83 ++++++++++---------- xen/arch/i386/setup.c | 4 +- xen/common/trace.c | 56 ++++++------- xen/include/hypervisor-ifs/dom0_ops.h | 8 +- xen/include/xeno/trace.h | 108 ++++++++++---------------- 6 files changed, 113 insertions(+), 148 deletions(-) diff --git a/tools/xentrace/Makefile b/tools/xentrace/Makefile index 52574e8e04..83dff0fa43 100644 --- a/tools/xentrace/Makefile +++ b/tools/xentrace/Makefile @@ -29,4 +29,4 @@ clean: $(RM) *.a *.so *.o *.rpm $(BIN) %: %.c $(HDRS) Makefile - $(CC) $(CFLAGS) -o $@ $< -lxc + $(CC) $(CFLAGS) -o $@ $< -L../xc/lib -lxc diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c index 9da21d6a81..526c8152fc 100644 --- a/tools/xentrace/xentrace.c +++ b/tools/xentrace/xentrace.c @@ -1,5 +1,4 @@ /****************************************************************************** - * * tools/xentrace/xentrace.c * * Tool for collecting trace buffer data from Xen. @@ -8,8 +7,7 @@ * * Author: Mark Williamson, mark.a.williamson@intel.com * Date: February 2004 - * - *****************************************************************************/ + */ #include #include @@ -25,7 +23,6 @@ #include "../xc/lib/xc_private.h" -#define TRACE_BUFFER /* need to define this for trace.h */ #include extern FILE *stdout; @@ -99,7 +96,7 @@ void print_rec(unsigned int cpu, struct t_rec *rec, FILE *out) * be dereferenced immediately, since it is a physical address of memory in Xen * space - they are used in this program to mmap the right area from /dev/mem. */ -struct t_buf *get_tbuf_ptrs() +unsigned long get_tbuf_ptrs(void) { int ret; dom0_op_t op; /* dom0 op we'll build */ @@ -112,7 +109,8 @@ struct t_buf *get_tbuf_ptrs() xc_interface_close(xc_handle); - if(ret) { + if ( ret != 0 ) + { PERROR("Failure to get trace buffer pointer from Xen"); exit(EXIT_FAILURE); } @@ -128,14 +126,14 @@ struct t_buf *get_tbuf_ptrs() * address space by memory mapping /dev/mem. Returns a pointer to the location * the buffers have been mapped to. */ -struct t_buf *map_tbufs(struct t_buf *tbufs_phys) +struct t_buf *map_tbufs(unsigned long tbufs_phys) { int dm_fd; /* file descriptor for /dev/mem */ struct t_buf *tbufs_mapped; dm_fd = open("/dev/mem", O_RDONLY); - - if(dm_fd < 0) { + if ( dm_fd < 0 ) + { PERROR("Open /dev/mem when mapping trace buffers\n"); exit(EXIT_FAILURE); } @@ -146,7 +144,8 @@ struct t_buf *map_tbufs(struct t_buf *tbufs_phys) close(dm_fd); - if(tbufs_mapped == MAP_FAILED) { + if ( tbufs_mapped == MAP_FAILED ) + { PERROR("Failed to mmap trace buffers"); exit(EXIT_FAILURE); } @@ -168,15 +167,15 @@ struct t_buf **init_bufs_ptrs(void *bufs_mapped) struct t_buf **user_ptrs; user_ptrs = (struct t_buf **)calloc(opts.num_cpus, sizeof(struct t_buf *)); - - if(!user_ptrs) { + if ( user_ptrs == NULL ) + { PERROR( "Failed to allocate memory for buffer pointers\n"); exit(EXIT_FAILURE); } /* initialise pointers to the trace buffers - given the size of a trace * buffer and the value of bufs_maped, we can easily calculate these */ - for(i = 0; idata - - (unsigned long)tbufs_phys - + (unsigned long)tbufs_mapped - ); - } + for ( i = 0; idata - + tbufs_phys + (unsigned long)tbufs_mapped); return data; } @@ -232,12 +227,13 @@ int *init_tail_idxs(struct t_buf **bufs) int i; int *tails = calloc(opts.num_cpus, sizeof(unsigned int)); - if(!tails) { + if ( tails == NULL ) + { PERROR("Failed to allocate memory for tail pointers\n"); exit(EXIT_FAILURE); } - for(i = 0; ihead; return tails; @@ -256,7 +252,7 @@ int monitor_tbufs(FILE *logfile) struct t_rec **data; /* pointers to the trace buffer data areas * where they are mapped into user space. */ int *tails; /* store tail indexes for the trace buffers */ - struct t_buf *tbufs_phys; /* physical address of the tbufs */ + unsigned long tbufs_phys; /* physical address of the tbufs */ /* setup access to trace buffers */ tbufs_phys = get_tbuf_ptrs(); @@ -268,18 +264,22 @@ int monitor_tbufs(FILE *logfile) tails = init_tail_idxs (meta); /* now, scan buffers for events */ - while(!interrupted) { - for(i = 0; i < opts.num_cpus; i++) { + while ( !interrupted ) + { + for ( i = 0; i < opts.num_cpus; i++ ) + { signed long newdata = meta[i]->head - tails[i]; signed long prewrap = newdata; /* correct newdata and prewrap in case of a pointer wrap */ - if(newdata < 0) { + if ( newdata < 0 ) + { newdata += meta[i]->size; prewrap = meta[i]->size - tails[i]; } - if(newdata >= opts.new_data_thresh) { + if ( newdata >= opts.new_data_thresh ) + { /* output pre-wrap data */ for(j = 0; j < prewrap; j++) print_rec(i, data[i] + tails[i] + j, logfile); @@ -316,22 +316,23 @@ error_t cmd_parser(int key, char *arg, struct argp_state *state) { settings_t *setup = (settings_t *)state->input; - switch(key) + switch ( key ) { case 't': /* set new records threshold for logging */ { char *inval; setup->new_data_thresh = strtol(arg, &inval, 0); - if(inval == arg) argp_usage(state); + if ( inval == arg ) + argp_usage(state); } - break; case 's': /* set sleep time (given in milliseconds) */ { char *inval; setup->poll_sleep = millis_to_timespec(strtol(arg, &inval, 0)); - if(inval == arg) argp_usage(state); + if ( inval == arg ) + argp_usage(state); } break; @@ -339,16 +340,19 @@ error_t cmd_parser(int key, char *arg, struct argp_state *state) { char *inval; setup->num_cpus = strtol(arg, &inval, 0); - if(inval == arg) argp_usage(state); + if (inval == arg ) + argp_usage(state); } break; case ARGP_KEY_ARG: - if(state->arg_num == 0) + { + if ( state->arg_num == 0 ) setup->outfile = arg; else argp_usage(state); - break; + } + break; default: return ARGP_ERR_UNKNOWN; @@ -413,9 +417,8 @@ int main(int argc, char **argv) argp_parse(&parser_def, argc, argv, 0, 0, &opts); - if(opts.outfile) { + if ( opts.outfile ) logfile = fopen(opts.outfile, "w"); - } /* ensure that if we get a signal, we'll do cleanup, then exit */ sigaction(SIGHUP, &act, 0); diff --git a/xen/arch/i386/setup.c b/xen/arch/i386/setup.c index 2e5c315530..8359fd086c 100644 --- a/xen/arch/i386/setup.c +++ b/xen/arch/i386/setup.c @@ -451,7 +451,5 @@ void __init start_of_day(void) watchdog_on = 1; -#ifdef TRACE_BUFFER - init_trace_bufs(); /* initialise trace buffers */ -#endif + init_trace_bufs(); } diff --git a/xen/common/trace.c b/xen/common/trace.c index 6e741b7f34..9a1d455631 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -1,5 +1,4 @@ /****************************************************************************** - * * common/trace.c * * Xen Trace Buffer @@ -15,12 +14,11 @@ * * See also include/xeno/trace.h and the dom0 op in * include/hypervisor-ifs/dom0_ops.h - * - *****************************************************************************/ + */ #include -#ifdef TRACE_BUFFER /* don't compile this stuff in unless explicitly enabled */ +#ifdef TRACE_BUFFER #include #include @@ -33,14 +31,11 @@ #include #include - - /* Pointers to the meta-data objects for all system trace buffers */ struct t_buf *t_bufs[NR_CPUS]; /* a flag recording whether initialisation has been done */ -atomic_t tb_init_done = ATOMIC_INIT(0); - +int tb_init_done = 0; /** * init_trace_bufs - performs initialisation of the per-cpu trace buffers. @@ -49,55 +44,52 @@ atomic_t tb_init_done = ATOMIC_INIT(0); * trace buffers. The trace buffers are then available for debugging use, via * the %TRACE_xD macros exported in . */ -void init_trace_bufs() +void init_trace_bufs(void) { - int i; - void *d; /* trace buffer area pointer */ + int i; + char *rawbuf; + struct t_buf *buf; - d = kmalloc(smp_num_cpus * TB_SIZE, GFP_KERNEL); - - if( d == NULL ) { + if ( (rawbuf = kmalloc(smp_num_cpus * TB_SIZE, GFP_KERNEL)) == NULL ) + { printk("Xen trace buffers: memory allocation failed\n"); return; } - for(i = 0; i < smp_num_cpus; i++) { - struct t_buf *buf = t_bufs[i] - = (struct t_buf *)( (unsigned int)d + TB_SIZE * i ); + for ( i = 0; i < smp_num_cpus; i++ ) + { + buf = t_bufs[i] = (struct t_buf *)&rawbuf[i*TB_SIZE]; - /* for use in Xen */ - buf->vdata = (struct t_rec *) - ( (unsigned int)buf + sizeof(struct t_buf) ); + /* For use in Xen. */ + buf->vdata = (struct t_rec *)(buf+1); buf->head_ptr = buf->vdata; - spin_lock_init(&buf->lock); + spin_lock_init(&buf->lock); - /* for use in user space */ + /* For use in user space. */ buf->data = (struct t_rec *)__pa(buf->vdata); - buf->head = 0; + buf->head = 0; - /* for use in both */ - buf->size = (TB_SIZE - sizeof(struct t_buf)) / sizeof(struct t_rec); + /* For use in both. */ + buf->size = (TB_SIZE - sizeof(struct t_buf)) / sizeof(struct t_rec); } printk("Xen trace buffers: initialised\n"); wmb(); /* above must be visible before tb_init_done flag set */ - atomic_set(&tb_init_done, 1); + tb_init_done = 1; } - - /** * get_tb_ptr - return physical address of the trace buffers. * * Called by the %DOM0_GETTBUFS dom0 op to fetch the physical address of the * trace buffers. */ -struct t_buf *get_tb_ptr() +unsigned long get_tb_ptr(void) { - /* a physical address (user space maps this using /dev/mem) */ - return (struct t_buf *)__pa(t_bufs[0]); + /* Return the physical address. */ + return __pa(t_bufs[0]); } -#endif /* #ifdef TRACE_BUFFER */ +#endif /* TRACE_BUFFER */ diff --git a/xen/include/hypervisor-ifs/dom0_ops.h b/xen/include/hypervisor-ifs/dom0_ops.h index aeb1f51917..f21c20fbcf 100644 --- a/xen/include/hypervisor-ifs/dom0_ops.h +++ b/xen/include/hypervisor-ifs/dom0_ops.h @@ -215,7 +215,7 @@ typedef struct dom0_pincpudomain_st typedef struct dom0_gettbufs_st { /* OUT variable - location of the trace buffers */ - struct t_buf *phys_addr; + unsigned long phys_addr; } dom0_gettbufs_t; typedef struct dom0_op_st @@ -244,8 +244,4 @@ typedef struct dom0_op_st } u; } dom0_op_t; - - - - -#endif +#endif /* __DOM0_OPS_H__ */ diff --git a/xen/include/xeno/trace.h b/xen/include/xeno/trace.h index c6a1a840b6..aa7ba5121c 100644 --- a/xen/include/xeno/trace.h +++ b/xen/include/xeno/trace.h @@ -1,5 +1,4 @@ /****************************************************************************** - * * include/xeno/trace.h * * Xen Trace Buffer @@ -17,29 +16,16 @@ * trace buffer contents can then be performed using a userland tool. * * See also common/trace.c and the dom0 op in include/hypervisor-ifs/dom0_ops.h - * - *****************************************************************************/ - -#ifdef TRACE_BUFFER + */ #ifndef __XENO_TRACE_H__ #define __XENO_TRACE_H__ -#ifdef __KERNEL__ - -#include -#include -#include -#include -#include -#include -#include - -#endif /* #ifdef __KERNEL__ */ - -/****************************************************************************** - * Data structure declarations - *****************************************************************************/ +/* + * How much space is allowed for a single trace buffer, including data and + * metadata (and maybe some waste). + */ +#define TB_SIZE PAGE_SIZE /* This structure represents a single trace buffer record. */ struct t_rec { @@ -48,37 +34,41 @@ struct t_rec { u32 d1, d2, d3, d4, d5; /* event data items */ }; -/* This structure contains the metadata for a single trace buffer. The head +/* + * This structure contains the metadata for a single trace buffer. The head * field, indexes into an array of struct t_rec's. */ struct t_buf { struct t_rec *data; /* pointer to data area. physical address - * for convenience in user space code */ + * for convenience in user space code */ unsigned int size; /* size of the data area, in t_recs */ unsigned int head; /* array index of the most recent record */ #ifdef __KERNEL__ struct t_rec *head_ptr; /* pointer to the head record */ - struct t_rec *vdata; /* virtual address pointer to data, - * for use in Xen */ + struct t_rec *vdata; /* virtual address pointer to data */ spinlock_t lock; /* ensure mutually exlusive access (for inserts) */ -#endif /* #ifdef __KERNEL__ */ +#endif /* never add anything here - the kernel stuff must be the last elements */ }; -/****************************************************************************** - * Functions - *****************************************************************************/ +#ifdef TRACE_BUFFER -#ifdef __KERNEL__ +#include +#include +#include +#include +#include +#include +#include /* Used to initialise trace buffer functionality */ -void init_trace_bufs(); +void init_trace_bufs(void); /* used to retrieve the physical address of the trace buffers */ -struct t_buf *get_tb_ptr(); +struct t_buf *get_tb_ptr(void); /** * trace - Enters a trace tuple into the trace buffer for the current CPU. @@ -92,19 +82,19 @@ struct t_buf *get_tb_ptr(); static inline int trace(u32 event, u32 d1, u32 d2, u32 d3, u32 d4, u32 d5) { extern struct t_buf *t_bufs[]; /* global array of pointers to bufs */ - extern atomic_t tb_init_done; /* set when buffers are initialised */ + extern int tb_init_done; /* set when buffers are initialised */ unsigned long flags; /* for saving interrupt flags */ struct t_buf *buf; /* the buffer we're working on */ struct t_rec *rec; /* next record to fill out */ - if(!atomic_read(&tb_init_done)) return -1; + if ( !tb_init_done ) + return -1; buf = t_bufs[smp_processor_id()]; rec = buf->head_ptr; spin_lock_irqsave(&buf->lock, flags); - /* interrupts _disabled locally_ during the following code */ rdtscll(rec->cycles); rec->event = event; @@ -116,45 +106,32 @@ static inline int trace(u32 event, u32 d1, u32 d2, u32 d3, u32 d4, u32 d5) wmb(); /* above must be visible before reader sees index updated */ - if( likely( buf->head_ptr < ( buf->vdata + buf->size - 1) ) ) { + if ( likely(buf->head_ptr < (buf->vdata + buf->size - 1)) ) + { buf->head_ptr++; buf->head++; - } else { - buf->head = 0; + } + else + { + buf->head = 0; buf->head_ptr = buf->vdata; } spin_unlock_irqrestore(&buf->lock, flags); - /* Interrupts now _re-enabled locally_ */ return 0; } - -#endif /* #ifdef __KERNEL__ */ - - -/****************************************************************************** - * Macros - *****************************************************************************/ - -/* How much space is allowed for a single trace buffer, including data and - * metadata (and maybe some waste). - */ -#define TB_SIZE PAGE_SIZE - -#ifdef __KERNEL__ - -/* avoids troubling the caller with casting their arguments to a trace macro */ +/* Avoids troubling the caller with casting their arguments to a trace macro */ #define trace_do_casts(e,d1,d2,d3,d4,d5) \ trace(e, \ - (unsigned long)d1, \ - (unsigned long)d2, \ - (unsigned long)d3, \ - (unsigned long)d4, \ - (unsigned long)d5) + (unsigned long)d1, \ + (unsigned long)d2, \ + (unsigned long)d3, \ + (unsigned long)d4, \ + (unsigned long)d5) -/* convenience macros for calling the trace function */ +/* Convenience macros for calling the trace function. */ #define TRACE_0D(event) trace_do_casts(event,0, 0, 0, 0, 0 ) #define TRACE_1D(event,d) trace_do_casts(event,d, 0, 0, 0, 0 ) #define TRACE_2D(event,d1,d2) trace_do_casts(event,d1,d2,0, 0, 0 ) @@ -162,13 +139,10 @@ static inline int trace(u32 event, u32 d1, u32 d2, u32 d3, u32 d4, u32 d5) #define TRACE_4D(event,d1,d2,d3,d4) trace_do_casts(event,d1,d2,d3,d4,0 ) #define TRACE_5D(event,d1,d2,d3,d4,d5) trace_do_casts(event,d1,d2,d3,d4,d5) -#endif /* #ifdef __KERNEL__ */ +#else -#endif /* #ifndef __XENO_TRACE_H__ */ +#define init_trace_bufs() ((void)0) -#else /* #ifdef TRACE_BUFFER */ - -/* define out macros so that they can be left in code when tracing is disabled */ #define TRACE_0D(event) ((void)0) #define TRACE_1D(event,d) ((void)0) #define TRACE_2D(event,d1,d2) ((void)0) @@ -176,4 +150,6 @@ static inline int trace(u32 event, u32 d1, u32 d2, u32 d3, u32 d4, u32 d5) #define TRACE_4D(event,d1,d2,d3,d4) ((void)0) #define TRACE_5D(event,d1,d2,d3,d4,d5) ((void)0) -#endif /* #ifdef TRACE_BUFFER */ +#endif /* TRACE_BUFFER */ + +#endif /* __XENO_TRACE_H__ */ -- 2.30.2